<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 在父组件的子组件标签上面加ref属性 -->
    <!-- this.$refs.xx获取子组件实例 -->
    <div id="app">
      <h3>获取子组件实例</h3>
      <child ref="abc"></child>

      <!-- 可以用ref属性来获取dom元素 -->
      <!-- 只能在mounted以后才能获取 -->
      <div class="box" ref="box">1234</div>
    </div>

    <script src="../Vue.js"></script>
    <script>
      const Child = {
        data() {
          return {
            num: 10,
          };
        },
        template: `
        <div>
          child
        </div>
      `,
      };

      new Vue({
        el: "#app",
        data: {},
        components: {
          Child,
        },
        mounted() {
          // console.log(this.$refs.abc);
          console.log(document.querySelector(".box"));
          console.log(this.$refs.box);
        },
      });
    </script>
  </body>
</html>
